package com.qf.java2102.qihaonan.hotel.dao.impl;

import com.qf.java2102.qihaonan.hotel.dao.IOrderDetailDao;
import com.qf.java2102.qihaonan.hotel.pojo.OrderDetail;
import com.qf.java2102.qihaonan.hotel.utils.JdbcUtils;

import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * @author qhn
 * @version 1.0
 */
public class OrderDetailDaoImpl implements IOrderDetailDao {

    private QueryRunner queryRunner = null;

    @Override
    public int save(OrderDetail orderDetail) throws SQLException {
        queryRunner = new QueryRunner(JdbcUtils.getDataSource());
        String sql = "INSERT INTO `t_order_detail` \n" +
                "\t(`order_detail_id`,`order_id`,`food_id`,`num`,`food_total_price`,`order_detail_create_time`,`order_detail_update_time`) \n" +
                "VALUES (?,?,?,?,?,?,?)";
        return queryRunner.update(JdbcUtils.getConnection(), sql,
                orderDetail.getOrderDetailId(), orderDetail.getOrderId(), orderDetail.getFoodId(), orderDetail.getNum(),
                orderDetail.getFoodTotalPrice(), orderDetail.getOrderDetailCreateTime(), orderDetail.getOrderDetailUpdateTime());
    }
}
